package main

import (
	"goGrpc/helloService/DataBaseUtils"
	KafkaTest "goGrpc/helloService/Kafka"
	"goGrpc/helloService/Provider"
	pb "goGrpc/proto/protoGo"
	"google.golang.org/grpc"
	"google.golang.org/grpc/grpclog"
	"log"
	"net"
)

const (
	// Address gRPC服务地址
	Address = "127.0.0.1:50051"
)

func main() {
	DataBaseUtils.NewMySqlConnect() // mysql初始化
	DataBaseUtils.NewEsConnect()    // es初始化
	DataBaseUtils.NewRedisConnect() // redis 初始化
	KafkaTest.ProducerInit()        //kafka 生产者初始化
	DataBaseUtils.NewNeo4jConnect() // 初始化neo4j
	go KafkaTest.ConsumerInit()     // kafka 消費者定时轮训
	log.Println("启动grpc")
	listen, err := net.Listen("tcp", Address)
	if err != nil {
		grpclog.Fatalf("Failed to listen: %v", err)
	}

	// 实例化grpc Server
	s := grpc.NewServer()

	// 注册HelloService
	pb.RegisterHelloServer(s, HelloProvider.HelloService)

	log.Print("监听 " + Address)
	s.Serve(listen)
}
